<#include "/common/_page.ftl"/>
<@page>
<div class="easyui-panel" data-options="fit:true,title:'${datatitle}'">
	<div class="easyui-layout" data-options="fit:true,border:false">
		<div data-options="region:'west',title:'对象列表',split:true,tools:'#typetools'" style="width:200px;">
			<div id="dl"></div>
		
		</div>            
		<div data-options="region:'center',title:'数据内容',border:false">
	    	<div id="contentpanel">
	    	
	    	</div>
		</div>   
	</div>
	
	<div id="typetools">
		<a id="btnAdd" href="javascript:void(0)" class="icon-add"></a>
		<a id="btnRemove" href="javascript:void(0)" class="icon-remove"></a>
	</div>
</div>
 
 

<div id="createDialog" class="easyui-dialog" title="创建对象"  data-options="iconCls:'icon-save',resizable:false,closed:true,modal:true,width: 350">
	<form id="dataForm">
		<div style="display: none;"><input id="form_id" name="form.id" class="form-id" value=""></div>
		<br/>
		<input id="form_name" name="form.name" class="easyui-textbox" data-options="label:'对象名称：',labelAlign:'right',required:true,validType:'areacode'" style="width:300px"> 
		<br/>
		<input id="form_label" name="form.label" class="easyui-textbox" data-options="label:'对象标签：',labelAlign:'right',required:true" style="width:300px">
		<div id="amssage" align="center"></div>			
		<br/>
		<div align="center">
		  <button type="button" id="btnDialogClose" name="btnClose"  class="btn btn-primary btn-sm close-dialog" >关闭</button>
		  <button type="submit" name="btnSubmit" class="btn btn-primary btn-sm">提交</button>
		</div>
	</form>
</div>

 
<script type="text/javascript">
$(function(){
	$.extend($.fn.validatebox.defaults.rules, {
       areacode : {
           validator : function(value) {
               return /^[a-zA-Z0-9]{2,20}$/gi.test(value);
           },
           message : '只允许2-20位字母或数字'
       }
   });

	$("#contentpanel").panel({fit:true});
	$('#dl').datalist({
		url:"${request.contextPath}/admin/object/getObjectList",
		textField:"text",
		valueField:"id",
	    lines: true,
	    onSelect:function(index, row){
	    	$("#contentpanel").panel("refresh","${request.contextPath}/admin/object/getBaseInfo?id="+row.id);
	    }
	});
	
	$("#btnDialogClose").on("click",function(){
		$("#dataForm").form("clear");
		$('#createDialog').dialog('close');
	});
	
	$("#btnAdd").on("click",function(){		
		$("#dataForm").form("clear");
		$('#createDialog').dialog('open'); 
	});
	
	$("#btnRemove").on("click",function(){		
		var select  = $('#dl').datalist("getSelected");
		if(select!=null){
			$.messager.confirm('Confirm','是否确认删除“'+ select.text +'”对象及数据?',function(r){
			    if (r){
			        alert(select.text);
			        var url="${request.contextPath}/admin/object/remove";
			        $.post(url,{"id":select.id},function(result){
			        	$('#dl').datalist("reload");
			        });
			    }
			});
		}		
	});
	
	$("#dataForm").submit(function(e){
		var url="${request.contextPath}/admin/object/save";
		$.post(url,$("#dataForm").serialize(),function(result){
			if(result.code==1){
				$('#dl').datalist("reload");
				$("#dataForm").form("clear");
				$('#createDialog').dialog('close');
			}else{
				
			}
		});
		return false;
	});
});
</script>
</@page>
